import {createSlice,PayloadAction} from '@reduxjs/toolkit'
import {produce} from 'immer'
export type QuestionSlice_StateType = {
    title:string,
    desc:string,
    jscode:string,
    csscode:string
}

export const QuestionSlice_initialValue:QuestionSlice_StateType = {
    title:'',
    desc:'',
    jscode:'',
    csscode:''
}

const QuestionSlice = createSlice({
    name:'QuestionSlice',
    initialState:QuestionSlice_initialValue,
    reducers:{
        setQuestion(state:QuestionSlice_StateType,action:PayloadAction<QuestionSlice_StateType>){
            return action.payload
        },
        changeTitleQuestion:produce((draft:QuestionSlice_StateType,action:PayloadAction<string>)=>{
            draft.title = action.payload
        })
    }
})


export const {setQuestion,changeTitleQuestion} = QuestionSlice.actions

export default QuestionSlice.reducer